package org.example;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Date;

public class Demo2 {
    public static void main(String[] args) throws Exception{
        Class.forName("com.mysql.jdbc.Driver");
        Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/dd?serverTimezone=GMT%2B8",
                "root","root");
        String sql = "SELECT * FROM student";
        PreparedStatement pst = conn.prepareStatement(sql);//alt+回车
        //查询
//        int i = pst.executeUpdate();添加、修改、删除
        ResultSet resultSet = pst.executeQuery();//返回结果集
        while (resultSet.next()){
            int id = resultSet.getInt("id");
            String name = resultSet.getString("name");
            double score = resultSet.getDouble("score");
            String nationality = resultSet.getString("nationality");
            boolean gender =  resultSet.getBoolean("gender");
            Date admission_time = resultSet.getDate("admission_time");
            System.out.println(id+":"+name+" "+nationality+" "+score+" "+gender+" "+admission_time);
        }
    }
}
